#include <stdlib.h>
//ten minutes

struct link{
	struct link* next;
	int data;
};	

struct link* rerverse(struct link* ln){
	if(ln==NULL)return NULL;
	struct link* cur;
	struct link* next;
	struct link* nn;

	cur=ln;
	next=cur->next;
	if(next==NULL)return ln;
	ln->next=NULL;
	while(next!=NULL && nn!=NULL){
		nn=next->next;
		next->next=cur;
		cur=next;
		next=nn;
	}
	return cur;
	
}

void print_link(struct link* ln){
	while(ln!=NULL){
		printf("%d\n",ln->data);
		ln=ln->next;
	}
}

int main(){
	struct link* ln[5];
	//=(struct link*)malloc(5*sizeof(struct link));
	int i;
	for(i=0;i<5;i++){
		ln[i]=(struct link*)malloc(sizeof(struct link));
	}
	
	for(i=0;i<4;i++){
		ln[i]->next=ln[i+1];	
		ln[i]->data=i;
	}
	ln[4]->next=NULL;
	ln[4]->data=4;
	print_link(ln[0]);
	struct link* tmp=rerverse(ln[0]);
	print_link(tmp);
	print_link(NULL);
	print_link(ln[0]);
}
